/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gimreader;

import javax.swing.tree.TreeNode;

/**
 *
 * @author pavel
 */
public class JobEntries {

    long starttime;
    //String action;                          // TODO replace with BYTE  by dictionary
    byte action;
    // 1 - "Job_Extract"
    // 2 - "ExtractedRows"
    // 3 - "Job_TransformGIM"
    // 4 - "TransformStep" 
    // 5 - "Job_AggregateGIM"
    // 6 - "AggHierarchy"
    // 7 - 
    // 8 - 
    // 9 -

    int logfile;                               // index to log file path from LOGS array
    int line;
    long endtime;
    int duration;
    int rows;
    int custom1;
    String custom2;
    String custom3;
    String comment;

    public JobEntries(int logfile, byte action, int line) {
        this.action = action;
        this.line = line;
        this.logfile = logfile;
        this.starttime = -1;
        this.endtime = -1;
        this.rows = 0;
        this.duration = -1;
        this.custom1 = -1;
    }

    public JobEntries() {
        this.starttime = -1;
        this.endtime = -1;
        this.rows = 0;
        this.duration = -1;
        this.custom1 = -1;
    }

    long GetStart() {
        return starttime;
    }

    void SetStart(long starttime) {
        this.starttime = starttime;
        this.SetDuration();
    }

    long GetEnd() {
        return endtime;
    }

    void SetEnd(long endtime) {
        this.endtime = endtime;
        this.SetDuration();
    }

    void SetComment(String comment) {
        this.comment = comment;
    }

    String GetComment() {
        return comment;
    }

    void SetCustom(int c1) {
        this.custom1 = c1;
    }

    int GetCustom() {
        return custom1;
    }

    void SetRows(int r) {
        this.rows = r;
    }

    int GetRows() {
        return this.rows;
    }

    int GetDuration() {
        return duration;
    }
    
    String GetNiceDuration(){
        if (duration > 86400000) {  
            return duration /1000 / 60 / 60/ 24 + "days " +(duration / 1000 / 60 / 60) % 24 + ":" + (duration / 1000 / 60) % 60 + ":" + duration / 1000 % 60;
        }else {
            return (duration / 1000 / 60 / 60) % 24 + ":" + (duration / 1000 / 60) % 60 + ":" + duration / 1000 % 60;
        }
    }

    // Job duration, -1 if no Start or End point in the log files
    void SetDuration() {
        if (this.endtime <= 0 || this.starttime <= 0) {
            this.duration = -1;
        } else {
            this.duration = (int) (this.endtime - this.starttime);
        }
    }

    void SetDuration(String duration) {
        this.duration = Integer.parseInt(duration);
    }

    void SetDuration(int duration) {
        this.duration = duration;
    }

    @Override
    public String toString() {
        //return action + "";

        //TODO implement CASE with dictionary 
        try {

            switch (action) {
                case 0:  // is not used
                    return "/";
                case 1:
                    return "Job_ExtractICON";
                //return file.isFile() ? new Integer((int)file.length()) : "-/-/-";
                case 2:
                    return GetComment();
                //return file.isFile() ?  "File" : "Directory";
                case 3:
                    return "Job_TransformGIM";
                //return new Date(file.lastModified());
                case 4:
                    return GetComment();
                case 5:
                    return "Job_AggregateGIM";
                case 6:
                    return GetComment();
            }
        } catch (SecurityException se) {
        }
        return action + " rows: " + rows + " cust1: " + custom1 + " comment: " + comment + " start: " + starttime + " end: " + endtime + " duration: " + duration + " log: " + logfile + " line: " + line;
    }
}
